<template>
  <el-dialog
    :title="!dataForm.projectId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="项目名称" prop="projectName"  width="80px">
      <el-input v-model="dataForm.projectName" placeholder="项目名称"></el-input>
    </el-form-item>
    <el-form-item label="教师姓名" prop="teacherId">
      <!-- <el-input v-model="dataForm.teacherId" placeholder="教师姓名"></el-input> -->
      <el-select v-model="dataForm.teacherId" filterable placeholder="请选择">
    <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.name"
      :value="item.id">
    </el-option>
  </el-select>
    </el-form-item>
    <el-form-item label="项目类别" prop="category">
      <!-- <el-input v-model="dataForm.category" placeholder="项目类别"></el-input> -->
      <el-select v-model="dataForm.category" placeholder="请选择">
    <el-option
      v-for="item in projecttypes"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
    </el-form-item>
    <el-form-item label="开始时间" prop="beginTime">
      <!-- <el-input v-model="dataForm.beginTime" placeholder="开始时间"></el-input> -->
      <el-date-picker
      v-model="dataForm.beginTime"
      type="datetime"
      placeholder="选择日期时间">
    </el-date-picker>
    </el-form-item>
    <el-form-item label="结束时间" prop="endTime">
      <!-- <el-input v-model="dataForm.endTime" placeholder="结束时间"></el-input> -->
      <el-date-picker
      v-model="dataForm.endTime"
      type="datetime"
      placeholder="选择日期时间">
    </el-date-picker>
    </el-form-item>
    <el-form-item label="鉴定时间" prop="appraisalTime">
      <!-- <el-input v-model="dataForm.appraisalTime" placeholder="鉴定时间"></el-input> -->
      <el-date-picker
      v-model="dataForm.appraisalTime"
      type="datetime"
      placeholder="选择日期时间">
    </el-date-picker>
    </el-form-item>
    <el-form-item label="鉴定结论" prop="appraisalConclusion">
      <!-- <el-input v-model="dataForm.appraisalConclusion" placeholder="鉴定结论"></el-input> -->
      <el-input
  type="textarea"
  :rows="2"
  placeholder="请输入内容"
  v-model="dataForm.appraisalConclusion">
</el-input>
    </el-form-item>
    <el-form-item label="获奖情况" prop="projectAward">
      <!-- <el-input v-model="dataForm.projectAward" placeholder="获奖情况"></el-input> -->
      <el-select v-model="dataForm.projectAward" placeholder="请选择">
    <el-option
      v-for="item in rewards"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
    </el-form-item>
    <!-- <el-form-item label="项目排名" prop="projectRanking">
      <el-input v-model="dataForm.projectRanking" placeholder="项目排名"></el-input>
    </el-form-item> -->
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        rewards:[{
          value: '国家级一等奖',
          label: '国家级一等奖'
        }, {
          value: '国家级二等奖',
          label: '国家级二等奖'
        }, {
          value: '国家级三等奖',
          label: '国家级三等奖'
        }, {
          value: '省级一等奖',
          label: '省级一等奖'
        }, {
          value: '省级二等奖',
          label: '省级二等奖'
        }, {
          value: '省级三等奖',
          label: '省级三等奖'
        } ],
        options:[],
         projecttypes: [{
          value: '纵向科研项目',
          label: '纵向科研项目'
        }, {
          value: '横向科研项目',
          label: '横向科研项目'
        }],
        visible: false,
        dataForm: {
          projectId: 0,
          projectName: '',
          teacherId: '',
          category: '',
          beginTime: '',
          endTime: '',
          appraisalTime: '',
          appraisalConclusion: '',
          projectAward: '',
          projectRanking: ''
        },
        dataRule: {
          projectName: [
            { required: true, message: '项目名称不能为空', trigger: 'blur' }
          ],
          teacherId: [
            { required: true, message: 'teacher基本信息id不能为空', trigger: 'blur' }
          ],
          category: [
            { required: true, message: '项目类别不能为空', trigger: 'blur' }
          ],
          beginTime: [
            { required: true, message: '开始时间不能为空', trigger: 'blur' }
          ],
          endTime: [
            { required: true, message: '结束时间不能为空', trigger: 'blur' }
          ],
          appraisalTime: [
            { required: true, message: '鉴定时间不能为空', trigger: 'blur' }
          ],
          appraisalConclusion: [
            { required: true, message: '鉴定结论不能为空', trigger: 'blur' }
          ],
          projectAward: [
            { required: true, message: '获奖情况不能为空', trigger: 'blur' }
          ],
          projectRanking: [
            { required: true, message: '项目排名不能为空', trigger: 'blur' }
          ]
        }
      }
    },
     created(){
      this.getteacherInfo()
    },
    methods: {
       getteacherInfo(){
        // 获取教师基本信息
        this.$http({
        url: this.$http.adornUrl('/teacherservice/teachertitle/teacher/info'),
        method: 'get',
        params: this.$http.adornParams({})
        }).then(({data}) => {
          console.log(data)
          this.options=data.data
          console.log("jdvnd",this.options)
        })
      

      },
      init (id) {
        this.dataForm.projectId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.projectId) {
            this.$http({
              url: this.$http.adornUrl(`/teacherservice/teacherproject/info/${this.dataForm.projectId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.projectName = data.teacherProject.projectName
                this.dataForm.teacherId = data.teacherProject.teacherId
                this.dataForm.category = data.teacherProject.category
                this.dataForm.beginTime = data.teacherProject.beginTime
                this.dataForm.endTime = data.teacherProject.endTime
                this.dataForm.appraisalTime = data.teacherProject.appraisalTime
                this.dataForm.appraisalConclusion = data.teacherProject.appraisalConclusion
                this.dataForm.projectAward = data.teacherProject.projectAward
                this.dataForm.projectRanking = data.teacherProject.projectRanking
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/teacherservice/teacherproject/${!this.dataForm.projectId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'projectId': this.dataForm.projectId || undefined,
                'projectName': this.dataForm.projectName,
                'teacherId': this.dataForm.teacherId,
                'category': this.dataForm.category,
                'beginTime': this.dataForm.beginTime,
                'endTime': this.dataForm.endTime,
                'appraisalTime': this.dataForm.appraisalTime,
                'appraisalConclusion': this.dataForm.appraisalConclusion,
                'projectAward': this.dataForm.projectAward,
                'projectRanking': this.dataForm.projectRanking
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
